package com.game.screen;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.game.GameJam;
import com.game.screen.level.LevelMap;
import com.game.screen.level.Obstacle;
import com.game.screen.level.LevelLoader;
import com.game.util.ArrayRenderer;
import com.game.util.Coord;

public class GameScreen extends Screen{

	public static float GRAVITY = -0.000001f;
	public static int time = 300;
	private Player player1 = new Player("cloud.png", 100, 300);
	public GameScreenBackground bg;
	private LevelLoader manager;
	private LevelMap map;
	
	public GameScreen(){
		bg = new GameScreenBackground("bg1.jpg", 0, 0);

		resetPlayer();
	}
	
	public void resetPlayer(){
		player1 = new Player("cloud.png", 100, 300);
		Player.asleep = true;
		Player.numBubbles = 2;

		bg.reset(0, 0);

		manager = new LevelLoader();
		
		try {
			map = manager.loadMap("/data/level1.txt");
		} catch (IOException ioe) {
			System.out.println ("GameScreen.java: Exception while loading map" + ioe.toString());
		}
	}
	
	public void display() {
		super.display();
		
		bg.display();
		
		if(Player.asleep){
			map.displayMap();
		}
		else{
			if(Player.numBubbles<7){			
				GameJam game = ((GameJam)pApplet);
				game.updateScreen(GameJam.GAME_OVER_SCREEN_OK);
			}
			else if(Player.numBubbles>=7 && Player.numBubbles<13 ){
				GameJam game = ((GameJam)pApplet);
				game.updateScreen(GameJam.GAME_OVER_SCREEN_GREAT);
			}
			else {
				GameJam game = ((GameJam)pApplet);
				game.updateScreen(GameJam.GAME_OVER_SCREEN_PERFECT);
			}

		}
		player1.update();
		player1.display();
	}

	public void update(){}
	
	public void onKeyPressed(char key, int keyCode){
		player1.onKeyPressed(key, keyCode);
	}
	
}
